﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_mutilQuestionInfoManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string mutil_question_title = "";

        System.Data.DataTable table1 = new System.Data.DataTable();
        int count = 0;//总记录的条数
        try
        {
            //填充数据
            int page = Int32.Parse(Request.QueryString["page"].ToString().Trim());
            int limit = Int32.Parse(Request.QueryString["limit"].ToString().Trim());

            if (Request.QueryString["mutil_question_title"] != null)
            {
                mutil_question_title = Request.QueryString["mutil_question_title"].ToString().Trim();
            }
            //question_type 
            //多选

            string sqlGetDataCount = "select count(*) from tb_mutil_questions ";
            List<string> wheres = new List<string>();

            if (mutil_question_title != "")
            {
                wheres.Add("mutil_question_title like '%" + mutil_question_title + "%'");
            }
            string wh = "";
            if (wheres.Count > 0)
            {
                wh = string.Join(" and ", wheres.ToArray());
                sqlGetDataCount = sqlGetDataCount + " where " + wh;
            }
            count = Int32.Parse(SqlServer.ExecuteScalar(sqlGetDataCount));
            int page_temp = page;
            int limit_temp = limit;
            if (count < page * limit)
            {
                limit = count - (page - 1) * limit;
            }
            page = (page_temp - 1) * limit_temp;

            string sql = "select top " + limit + " mutil_question_id ,'多选题' as question_type, mutil_question_title , option_a, option_b ,option_c, option_d ,course_id ,correct_answer from tb_mutil_questions";

            if (wheres.Count > 0)
            {
                sql = sql + " where " + wh + " and mutil_question_id not in (select top " + page + "  mutil_question_id from tb_mutil_questions " + " where " + wh + ")";
            }
            else
            {
                sql = sql + " where mutil_question_id not in (select top " + page + "  mutil_question_id from tb_mutil_questions)";
            }
            table1 = SqlServer.GetDataTable(sql);
        }
        


        catch (Exception ex)
        {
            Response.Write("<script>alert('有错误')</script>");
            Response.End();
        }
        string a = Json.ToJson(table1, count);
        Response.Write(Json.ToJson(table1, count));
        Response.End();


    }
}